package com.example.controller;


import com.example.annotation.AuthConfig;
import com.example.annotation.RepeatSubmit;
import com.example.entity.Comment;
import com.example.service.ICommentService;
import com.example.utils.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王鹤蒲
 * @since 2023-08-31
 */
@Api(tags = "评论信息API",description="提供评论信息相关的 REST API")
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private ICommentService iCommentService;

    @RequestMapping(value="/save",method= RequestMethod.POST)
    @RepeatSubmit(lockTime = 5)
    @ResponseBody
    public R saveComment(@RequestBody Comment comment) {
        return iCommentService.saveComment(comment);
    }

    @RequestMapping(value="/delete/{id}",method= RequestMethod.DELETE)
    @ResponseBody
    public R deleteById(@PathVariable("id") Integer id) {
        return iCommentService.deleteById(id);
    }

    @RequestMapping(value="/deleteBatch",method= RequestMethod.POST)
    @ResponseBody
    public R deleteByIds(@RequestBody Integer[] ids) {
        return null;
    }

    @RequestMapping(value="/tree/{articleId}",method= RequestMethod.GET)
    @ResponseBody
    @AuthConfig
    public R queryCommentDetail(@PathVariable("articleId")Integer articleId) {
        return iCommentService.queryArticleComments(articleId);
    }
}

